<?php
namespace Api\Controller;
use Think\Controller;
class PersonController extends BaseController {

    /**
     *   获取所有的喜爱的照片
     *
     */


    /**
     *  查看我的浏览足迹
     */
    public function getMyLike(){
        $openid = $_REQUEST['openid'];
        $list =  M('w_like')
            ->join('__WORKS__ ON __W_LIKE__.wid = __WORKS__.id')
            ->where("qi_w_like.uid = '$openid'")
            ->field('qi_works.id,qi_works.name,qi_works.image')
            ->order('qi_w_like.id desc')
            ->select();

        if($list){
            echo json_encode(array('list'=>$list,'err'=>'获取成功！'));
        }else{
            echo json_encode(array('status'=>404,'err'=>'获取失败！'));
        }
    }




    /**
     *   获取所有的活动
     */
    public function getAllAc(){
        $list = M('activity')->field('id,name,start_time,end_time,image')->order('id desc')->select();
        foreach($list as &$item){
            $item['stime'] =  date('Y-m-d', strtotime($item['start_time']));
            $item['etime'] =  date('Y-m-d', strtotime($item['end_time']));
        }
        if($list){
            echo json_encode(array('list'=>$list,'err'=>'获取成功！'));
        }else{
            echo json_encode(array('status'=>404,'err'=>'获取活动失败！'));
        }
    }


    /**
     *   获取活动详情图片
     */
     public function getAcImage(){
         $id = $_REQUEST['id'];
         $list = M('activity')->where("id = '$id'")->find();
         $imageA =  $list['imagea'];
         if($list){
             echo json_encode(array('aImage'=>$imageA,'err'=>'获取成功！'));
         }else{
             echo json_encode(array('status'=>404,'err'=>'获取活动失败！'));
         }
     }



     /**
      *   提交信息
      */
     public function inforSubmit(){
         $openid = $_REQUEST['openid'];
         $phone = $_REQUEST['tel'];
         $name = $_REQUEST['name'];
         if(!$openid || !$phone || !$name){
             echo json_encode(array('status'=>404,'err'=>'数据不能为空！'));
         }
         $data['openid'] = $openid;
         $data['phone'] = $phone;
         $data['name'] = $name;
         $list = M('ac_user')->where($data)->select();
         if($list){
             echo json_encode(array('status'=>404,'err'=>'请不要重复提交！'));
         }else{
             $data['create_at'] = date('Y-m-d H:i:s',time());
             $a = M('ac_user')->add($data);
             if($a){
                 echo json_encode(array('status'=>200,'err'=>'提交成功！'));
             }else{
                 echo json_encode(array('status'=>404,'err'=>'请不要重复提交！'));
             }
         }
     }






    /**
     *   提交报价信息
     */
    public function inforSubmitTime(){
        $openid = $_REQUEST['openid'];
        $phone = $_REQUEST['phone'];
        $name = $_REQUEST['name'];
        $time = $_REQUEST['time'];
        $city = $_REQUEST['city'];
        if(!$openid || !$phone || !$name){
            echo json_encode(array('status'=>404,'err'=>'数据不能为空！'));
        }
        $data['openid'] = $openid;
        $data['phone'] = $phone;
        $data['name'] = $name;
        $data['city'] = $city;
        $data['time'] = $time;
        $list = M('ac_user_time')->where($data)->select();
        if($list){
            echo json_encode(array('status'=>404,'err'=>'请不要重复提交！'));
        }else{
            $data['create_at'] = date('Y-m-d H:i:s',time());
            $a = M('ac_user_time')->add($data);
            if($a){
                echo json_encode(array('status'=>200,'err'=>'提交成功！'));
            }else{
                echo json_encode(array('status'=>404,'err'=>'请不要重复提交！'));
            }
        }
    }


     /**
      *   点击获取所有的小程序优惠券
      */
     public function getC(){
        $cid = $_REQUEST['cid'];
        $openid = $_REQUEST['openid'];
        $a['cid'] = $cid;
        $a['openid'] = $openid;
        $co = M('co_get')->where($a)->select();
        if(!$co){
            echo json_encode(array('status'=>204,'err'=>'已经获取过该优惠券！'));
        }else{
            $b = M('co_get')->add($a);
            if($b){
                echo json_encode(array('status'=>204,'err'=>'获取成功！'));
            }else{
                echo json_encode(array('status'=>204,'err'=>'获取优惠券失败！'));
            }
        }
     }


}
